InboxType

PackageAxial.ElmishFlows

Inbox

Inbox<'value> is one-way, drop-visible mail into an Elmish program: one queue, one reader, owned by a scope. Use it for values that arrive from outside update — a host callback, another library's event, a search box whose input must never block the UI thread. For work distribution or back-pressure between fibers, use Queue directly.

Create inboxes

Build the inbox in the scope that shuts it down. A layer given to ElmishRuntime.startLayer is provisioned in the runtime's root scope, so an inbox built there stays open for the program and is shut down with the runtime. The environment field is filled with let! commands = Inbox.scopedSliding 1 inside the layer's flow { }, and nothing has to register the inbox with the runtime afterwards.

scopedWith takes the QueueStrategy itself. The named constructors are the four strategies:

  • scopedSliding capacity keeps the newest pending value and evicts the oldest, so a burst collapses to the latest request.
  • scopedDropping capacity keeps the oldest pending value and refuses a newer offer.
  • scopedBounded capacity waits while the mailbox is full, so every value is delivered. Do not offer to it from a Cmd: a command runs on the dispatch thread and would wait there. Offer from a fiber instead.
  • scopedUnbounded() never waits and grows with the backlog.

create capacity runtime remains for a host that already holds the runtime. It drops the newest offer (QueueStrategy.Dropping) and shuts the inbox down when the runtime stops.

Offer values

  • offer value inbox is an Elmish command: update returns it and the offer reaches the mailbox in dispatch order.
  • post value inbox offers immediately and reports whether the mailbox accepted the value, for a synchronous callback that cannot return a command.

Read the mailbox

stream inbox is the inbox as a FlowStream: every accepted value, in the order it was offered. Read it once, because two readers split the mail between them. Pipe it through FlowStream.debounce and FlowStream.switchMapFlow for search-as-you-type, then run it with Sub.OfFlowStream.subscribe.

dropped inbox counts the values the mailbox could not keep: an offer refused while it was full, or the pending value a sliding inbox evicted to take a newer one. Surface it next to the search status so a coalesced search is visible instead of silent.

Specification

Kind
Type
Members
11
Examples
0
scopedWithSignature
Inbox.scopedWith strategy
scopedSlidingSignature
Inbox.scopedSliding capacity
scopedDroppingSignature
Inbox.scopedDropping capacity
scopedBoundedSignature
Inbox.scopedBounded capacity
scopedUnboundedSignature
Inbox.scopedUnbounded ()

Summary

NameSignatureSynopsis
Create inboxes
scopedWithInbox.scopedWith strategyAn inbox whose queue is shut down when the current scope closes, with the given strategy.
scopedSlidingInbox.scopedSliding capacityA non-blocking inbox in which the newest pending value survives a burst; the oldest is dropped.
scopedDroppingInbox.scopedDropping capacityA non-blocking inbox in which the oldest pending value survives; a newer offer is dropped.
scopedBoundedInbox.scopedBounded capacityA lossless inbox in which an offer waits while the mailbox is full.
scopedUnboundedInbox.scopedUnbounded ()A lossless inbox that never waits; memory grows with the backlog.
createInbox.create capacity runtimeAn inbox shut down by the runtime instead of a scope, for a host that already holds the runtime.
Offer values
postInbox.post value inboxOffers a value; returns whether the mailbox took it, false when it is full or shut down.
offerInbox.offer value inboxThe same offer, as a command for update to return.
Read the mailbox
streamInbox.stream inboxThe mailbox as a stream: every accepted value, in the order it was offered.
droppedInbox.dropped inboxValues the mailbox could not keep, whether refused or evicted by a sliding mailbox.
Droppedthis.DroppedValues the mailbox could not keep: an offer refused while it was full, or the pending value a sliding mailbox evicted to take a newer one.

Create inboxes

Build the mailbox in the scope that will shut it down, naming its overflow strategy.

kind:membertask:create

scopedWith

Inbox.scopedWith strategy
Member
An inbox whose queue is shut down when the current scope closes, with the given strategy.

Parameters

NameTypeDescription
strategyQueueStrategyWhat happens when the mailbox is full: wait, slide, drop, or grow.

Returns

Flow<'env, Never, Inbox<'value>>
kind:membertask:create

scopedSliding

Inbox.scopedSliding capacity
Member
A non-blocking inbox in which the newest pending value survives a burst; the oldest is dropped.

Parameters

NameTypeDescription
capacityint

Returns

Flow<'env, Never, Inbox<'value>>
kind:membertask:create

scopedDropping

Inbox.scopedDropping capacity
Member
A non-blocking inbox in which the oldest pending value survives; a newer offer is dropped.

Parameters

NameTypeDescription
capacityint

Returns

Flow<'env, Never, Inbox<'value>>
kind:membertask:create

scopedBounded

Inbox.scopedBounded capacity
Member
A lossless inbox in which an offer waits while the mailbox is full.

Parameters

NameTypeDescription
capacityint

Returns

Flow<'env, Never, Inbox<'value>>
kind:membertask:create

scopedUnbounded

Inbox.scopedUnbounded ()
Member
A lossless inbox that never waits; memory grows with the backlog.

Parameters

NameTypeDescription
unit

Returns

Flow<'env, Never, Inbox<'value>>
kind:membertask:create

create

Inbox.create capacity runtime
Member
An inbox shut down by the runtime instead of a scope, for a host that already holds the runtime.

Parameters

NameTypeDescription
capacityint
runtimeElmishRuntime<'env>

Returns

Inbox<'value>

Offer values

Hand values to the program from update or from a synchronous callback.

kind:membertask:offer

post

Inbox.post value inbox
Member
Offers a value; returns whether the mailbox took it, false when it is full or shut down.

Parameters

NameTypeDescription
value'value
inboxInbox<'value>

Returns

bool
kind:membertask:offer

offer

Inbox.offer value inbox
Member
The same offer, as a command for update to return.

Parameters

NameTypeDescription
value'value
inboxInbox<'value>

Returns

Cmd<'msg>

Read the mailbox

Read values as a stream and count the offers a full mailbox could not keep.

kind:membertask:read

stream

Inbox.stream inbox
Member
The mailbox as a stream: every accepted value, in the order it was offered.

Parameters

NameTypeDescription
inboxInbox<'value>

Returns

FlowStream<'env, 'error, 'value>
kind:membertask:read

dropped

Inbox.dropped inbox
Member
Values the mailbox could not keep, whether refused or evicted by a sliding mailbox.

Parameters

NameTypeDescription
inboxInbox<'value>

Returns

int64
kind:membertask:read

Dropped

this.Dropped
Member
Values the mailbox could not keep: an offer refused while it was full, or the pending value a sliding mailbox evicted to take a newer one.

Returns

int64